<?php

namespace app\common\model\callback;


use app\common\model\auth\Admin;
use app\common\model\BaseModel;
use app\common\model\media_account\MediaAccount;
use app\common\model\promotion\PromotionLink;
use app\common\model\quickapp\Quickapp;
use app\common\model\order\Order;
use app\common\model\return_rule\ReturnRule;


/**
 * OrderCallback模型
 * Class OrderCallback
 * @package app\common\model
 */
class OrderCallback extends BaseModel
{

    protected $name = 'order_callback';


    public function getDyeingTimeAttr($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    public function getReportingTimeAttr($value, $data)
    {
        if (!empty($data['reporting_time'])) {
            $data['reporting_time'] = date('Y-m-d H:i:s', $data['reporting_time']);
        }else{
            $data['reporting_time'] = '';
        }
        return $data['reporting_time'];
    }
    public function getPayTimeAttr($value, $data)
    {
        if (!empty($data['pay_time'])) {
            $data['pay_time'] = date('Y-m-d H:i:s', $data['pay_time']);
        }
        return $data['pay_time'];
    }


    /**
     * 回传渠道
     *
     * @return \think\model\relation\HasOne
     */
    public function channel()
    {
        return $this->hasOne(ReturnRule::class, 'id', 'return_rule_id');
    }


    /**
     * 快应用
     *
     * @return \think\model\relation\HasOne
     */
    public function quickapp()
    {
        return $this->hasOne(Quickapp::class, 'id', 'platform');
    }


    /**
     * 订单
     *
     * @return \think\model\relation\HasOne
     */
    public function orders()
    {
        return $this->hasOne(Order::class, 'id', 'order_id');
    }


    /**
     * 媒体账户
     *
     * @return \think\model\relation\HasOne
     */
    public function account()
    {
        return $this->hasOne(MediaAccount::class, 'id', 'media_account_id');
    }


    /**
     * 推广链
     *
     * @return \think\model\relation\HasOne
     */
    public function link()
    {
        return $this->hasOne(PromotionLink::class, 'id', 'promotion_link_id');
    }

    /**
     * admin
     *
     * @return \think\model\relation\HasOne
     */
    public function admin()
    {
        return $this->hasOne(Admin::class, 'id', 'admin_id');
    }
}
